Release 10.1A: OpenEdge Development:
Messaging and ESB


Publishing, receiving, and processing a StreamMessage

The procedures example8.p and example9.p (1 of 2) publish, receive, and process a StreamMessage.

To run example8.p and example9.p:

  1. Connect to the Sportsdatabase.
  2. Run example9.p (1 of 2) to receive the StreamMessage containing the customer names and numbers, as shown:
  3. example9.p
    /* Receives a Stream message. */ 
    DEFINE VARIABLE pubsubsession AS HANDLE. 
    DEFINE VARIABLE consumerH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/pubsubsession.p PERSISTENT SET pubsubsession  
                                      ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN pubsubsession ("localhost:2506"). 
    RUN beginSession IN pubsubsession. 
    /* Subscribe to the newCustomers topic. The newCustHandler internal
       procedure handles the list of new customers. 
    */ 
    RUN createMessageConsumer IN pubsubsession ( 
                        THIS-PROCEDURE,    /* This proc will handle it */ 
                        "newCustHandler",  /* name of internal procedure */ 
                        OUTPUT consumerH). 
    RUN subscribe IN pubsubsession (
                          "NewCustomers", /* name of topic */ 
                          ?,              /* Subscription is not durable*/ 
                          ?,              /* No message selector. */ 
                          no,             /* Want my own messages too */ 
                          consumerH).     /* handles the messages */ 
    /* Start receiving messages */ 
    RUN startReceiveMessages IN pubsubsession. 
    /* Wait to receive the messages. Any other IO-blocked statements can be
       used for receiving messages.
    */ 
    WAIT-FOR u1 OF THIS-PROCEDURE. 
    
    PROCEDURE newCustHandler: 
    DEFINE INPUT PARAMETER messageH AS HANDLE. 
    DEFINE INPUT PARAMETER msgConsumerH AS HANDLE. 
    DEFINE OUTPUT PARAMETER replyH AS HANDLE. 
     /* Display the stream of customer names and customer numbers. */ 
     /* The moveToNext function moves the cursor to the next item in */ 
     /* the stream and returns the data type of that item.          */ 
     /* We assume the reply is not required. */ 
     IF NOT  DYNAMIC-FUNCTION('getMessageType':U IN messageH) = 
                                                     "StreamMessage" 
          THEN RETURN. 
     /* Note that the 'moveToNext' functions returns the item's data type. */ 
     DO WHILE NOT  DYNAMIC-FUNCTION('endOfStream':U IN messageH) WITH DOWN: 
        DISPLAY DYNAMIC-FUNCTION('moveToNext':U IN messageH)   
                DYNAMIC-FUNCTION('readChar':U IN messageH)  
                DYNAMIC-FUNCTION('moveToNext':U IN messageH)   
                DYNAMIC-FUNCTION('readInt':U IN messageH). 
        DOWN. 
     END. 
     RUN deleteMessage IN messageH. 
     APPLY "U1" TO THIS-PROCEDURE. 
    END. /* newCustHandler */ 
    

  4. Run example8.p to publish a StreamMessage containing customer names and numbers, as shown:
  5. example8.p 
    /* Publishing a Stream message. */ 
    DEFINE VARIABLE pubsubsession AS HANDLE. 
    DEFINE VARIABLE messageH AS HANDLE. 
    /* Creates a session object. */ 
    RUN jms/pubsubsession.p PERSISTENT SET pubsubsession  
                                      ("-H localhost -S 5162 "). 
    RUN setBrokerURL IN pubsubsession ("localhost:2506"). 
    RUN beginSession IN pubsubsession. 
    /* Create a stream message */ 
    RUN createStreamMessage IN pubsubsession (OUTPUT messageH). 
    /* Load the message with a list of customer names and cust-nums. */ 
    FOR EACH customer: 
       RUN writeString IN messageH (customer.name). 
       RUN writeInt IN messageH (customer.cust-num). 
    END. 
    /* Publish the message on the NewCustomers topic. */ 
    RUN publish IN pubsubsession ("NewCustomers", messageH, ?, ?, ?). 
    


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095